﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Limestone;
using Limestone.MVC;

namespace SampleSite
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {

            // resolve the pagestubcache with autoFac
            var pageStubCache = (IPageStubCache)DependencyResolver.Current.GetService(typeof(IPageStubCache));
            var pageProvider = (IPageProvider)DependencyResolver.Current.GetService(typeof(IPageProvider));

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{resource}.aspx");

            routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(jpg|gif|jpeg|png|js|css|htm|html|htc|flv|swf|ico|bmp|xml)$" });

            // explicitly adding routes as the page catchall route below otherwise will get em all

            // handle pages using the OrderForm template
            //routes.MapRoute("orderForm",
            //                "{*pagepath}",
            //                new { controller = "Order", action = "PlaceOrder" },
            //                new { pagePath = new HandledPagePathConstraint(pageProvider, "OrderForm") }
            //    );

            // all other pages will go to the PageController
            routes.MapRoute("Pages",
                            "{*pagepath}",
                            new { controller = "Page", action = "OpenPage" },
                            new { pagePath = new PagePathConstraint(pageStubCache) }
                );

            // will probably never reach here...
            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
                );


        }
    }
}